package jumpingnotes.storage;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public interface StorageService {
	/**
	 * Return the resource repository folder.
	 * @return
	 */
	String getRepoDir();
	
	/**
	 * Return the temporary folder.
	 * @return
	 */
	String getTmpDir();

	/**
	 * Save storage object from stream. The stream will NOT be closed.
	 * @param type
	 * @param subType TODO
	 * @param uuid
	 * @param inStream
	 * @return false if the storage object already exists.
	 * @throws UnsupportedStorageObject
	 * @throws IOException
	 */
	boolean saveStream(int type, int subType, String uuid, InputStream inStream)
		throws UnsupportedStorageObject, IOException;
	
	/**
	 * Load storage object to stream. The stream will NOT be closed.
	 * @param type
	 * @param subType TODO
	 * @param uuid
	 * @param outStream
	 * @return false if the storage object is not found.
	 * @throws UnsupportedStorageObject
	 * @throws IOException
	 */
	boolean loadStream(int type, int subType, String uuid, OutputStream outStream)
		throws UnsupportedStorageObject, IOException;
	
	/**
	 * Get the size of the storage object.
	 * @param type
	 * @param subType
	 * @param uuid
	 * @return
	 * @throws UnsupportedStorageObject
	 */
	long getObjectSize(int type, int subType, String uuid)
		throws UnsupportedStorageObject;
	
	/**
	 * Save a temporary object to persistent storage in resource
	 * repository.
	 * @param type
	 * @param tmpUuid
	 * @param persistUuid
	 * @return false if the storage object already exists.
	 * @throws UnsupportedStorageObject
	 * @throws IOException
	 */
	boolean persistTmpObject(int type, String tmpUuid, String persistUuid)
		throws UnsupportedStorageObject, IOException;
}
